package com.zlc.atonce.huarongdao.algorithme;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Node {
    String data;
    Node pre;

    Node() {
    }

    public Node(String data, Node pre) {
        this.data = data;
        this.pre = pre;
    }

    public Node(String data) {
        this.data = data;
    }

    public int size() {
        if (pre == null) {
            return 1;
        } else {
            return 1 + pre.size();
        }
    }

    public List<String> toList() {
        Node n = this;
        ArrayList<String> re = new ArrayList<>();
        while (n != null) {
            re.add(n.data);
            n = n.pre;
        }
        Collections.reverse(re);
        return re;
    }

    @Override
    public String toString() {
        if (this.pre == null) {
            return data;
        }
        return pre + " --> " + data;
    }


}
